<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var obj1 = {
        name: "张三",
        age: 18,
        sex: "男",
      };
      var obj2 = {
        name: "韩梅梅",
      };
      //题1：
      function getObjCount(obj) {
        // 实现传递一个对象，获取对象有多少属性名
        // code写代码...
        var sum = 0;
        for (var n in obj) {
          sum++;
        }
        return sum;
      }
      console.log(getObjCount(obj1)); //打印3
      console.log(getObjCount(obj2)); //打印1
      //题2：
      function getCountByNumber(n) {
        // 实现n个数的累加 如：输入2：1+2，输入3：1+2+3，输入100：1+2+3+...+100
        // code写代码...
        var sum = 0;
        for (var i = 1; i <= n; i++) {
          sum = sum + i;
        }
        return sum;
      }

      console.log(getCountByNumber(100)); //打印5050
      console.log(getCountByNumber(2)); //打印3
      //题3：
      function getCountByNumber11(n) {
        // 实现n个数中能被11的整除的数的累加
        //  如：输入10：0，输入11：11，输入22：11+22=33，输入100：11+22+33+44...
        // code写代码...
        var sum = 0;
        for (var i = 1; i <= n; i++) {
          if (i % 11 == 0) {
            sum = sum + i;
          }
        }

        return sum;
      }
      console.log(getCountByNumber11(10)); //0
      console.log(getCountByNumber11(11)); //11
      console.log(getCountByNumber11(22)); //11
      console.log(getCountByNumber11(100)); //495
      //题4：
      function getCountByNumberXY(x, y) {
        // 实现x个数中能被y的整除的数的累加
        //  如：输入2：1+2，输入3：1+2+3，输入100：1+2+3+...+100
        // code写代码...
        var sum = 0;
        for (var i = 1; i <= x; i++) {
          if (i % y == 0) {
            sum = sum + i;
          }
        }

        return sum;
      }
      console.log(getCountByNumberXY(10, 11)); //0
      console.log(getCountByNumberXY(11, 11)); //11
      console.log(getCountByNumberXY(100, 11)); //495
      console.log(getCountByNumberXY(100, 2)); //2550
    </script>
  </body>
</html>
